package com.socket.aop

import com.corundumstudio.socketio.AckRequest
import com.corundumstudio.socketio.SocketIOClient
import com.yfree.config.YConfig
import com.yfree.socket.YSocketManager
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.context.event.ApplicationStartedEvent
import org.springframework.context.ApplicationListener
import org.springframework.stereotype.Component

@Component
class ApplicationStartAop : ApplicationListener<ApplicationStartedEvent> {
    @Value("\${spring.profiles.active}")
    private lateinit var active: String

    override fun onApplicationEvent(event: ApplicationStartedEvent) {
        YConfig.DEBUG = active != "release"
        YConfig.Socket.host = "localhost"
        YConfig.Socket.port = 8301
        YSocketManager.init(YConfig.Socket.host, YConfig.Socket.port) { socketIOClient: SocketIOClient, message: String, ackRequest: AckRequest ->
            YSocketManager.log("client:${socketIOClient.sessionId}:${message}")
        }
    }
}
